// 封装和文章相关的接口函数

import { getArticleDetailUrl, getArticlesUrl, getChannelUrl, getCreateArticleUrl, getDeleteArticleUrl, getUpdateArticleUrl } from "@/constants/apiconfig"
import { request } from "@/utils"

// 1. 获取频道列表
export function getChannelAPI () {
  const channelUrl = getChannelUrl()
  return request({
    url: channelUrl.url,
    method: channelUrl.method
  })
}

// 2. 提交文章表单

export function createArticleAPI (data) {
  const createArticleUrl = getCreateArticleUrl()
  return request({
    url: createArticleUrl.url,
    method: createArticleUrl.method,
    data
  })
}

// 更新文章表单

export function updateArticleAPI (data) {
  const updateArticleUrl = getUpdateArticleUrl(data)
  return request({
    url: updateArticleUrl.url,
    method: updateArticleUrl.method,
    data
  })
}


// 获取文章列表

export function getArticleListAPI (params) {
  const articleUrl = getArticlesUrl()
  return request({
    url: articleUrl.url,
    method: articleUrl.method,
    params
  })
}


// 删除文章

export function delArticleAPI (id) {
  const deleteArticleUrl = getDeleteArticleUrl()
  return request({
    url: deleteArticleUrl.url,
    method: deleteArticleUrl.method
  })
}


// 获取文章详情

export function getArticleById (id) {
  const articleDetailUrl = getArticleDetailUrl(id)
  return request({
    url: articleDetailUrl.url
  })
}

